package chapter6;

import java.util.Scanner;

/****************************************************************
 * Author：icynlau
 * Description: 检测密码
 * Date:2021/4/4
 * ***************************************************************
 */
public class exc6_18 {
	
	public static boolean detect(String pwd) {
		//pwd  password
		boolean flag=true;
		
		if(pwd.length()<8) {
			
			System.out.print("Valid Password  密码长度少于8位字符");
			flag=false;
			return flag;
		}
		
		int n=0;   //计算数字数量
		
		for(int i=0;i<pwd.length();i++) {
			if(  ! (     Character.isDigit(pwd.charAt(i))   )  &&  !  (   Character.isLetter(pwd.charAt(i))   )) {
				
				System.out.print("Valid Password  密码必须仅含数字和字母");
				flag=false;
				return flag;
			}
			
			if(  Character.isDigit(pwd.charAt(i))  ) {
				
				n++;
				
			}
		}
		
		if(n<2) {
			
			System.out.print("Valid Password  密码必须至少包含两个数字");
			flag=false;
			return flag;
		}
		
		
		return flag;
	}
	
	
	public static void main(String[]  args) {
		
		Scanner input=new Scanner(System.in);
		
		System.out.print("Enter  a pwd :"
				+ "\n");
		
		String pwd=input.nextLine();
		
		if(detect(pwd)) {
			
			System.out.print("Valid Password.\n");
			
		}
		
	}

}
